<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Finance，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="finance_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/finance-list/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',				 
					  showFooter: true" >
		<#include "/common/thead.html">
	</table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        项目名称:<input class="easyui-textbox" style="width:120px" id="pro_name_like">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>

<#-- <#include "/common/dlg.html">-->


<!-- 按钮操作 -->
<script type="text/javascript">
	var url;

    //新增
    $('#add').click(function () {
        var url = '/finance-add?id=-1';
        var index = layer.open({
            title:'项目修改',
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });
	
    //编辑
    $("#edit").click(function () {
        var row = $('#finance_table').datagrid('getSelected');
        if (row){
            var url = '/finance-update/'+row.id;
            var index = layer.open({
                title:'用户修改',
                type: 2,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg("请选择需要编辑的项目",{icon: 2})
        }
        $('#finance_table').datagrid('reload');
    })
    //行复制
    $("#copy").click(function () {
        var row = $('#finance_table').datagrid('getSelected');
        if (row){
            url = '/finance-add?id='+row.id+"&sql=copy";
            var index = layer.open({
                title:'用户修改',
                type: 2,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg("请选择需要复制的行的项目",{icon: 2})
        }
        $('#finance_table').datagrid('reload');
    })
	
	function save(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
				$('#dlg').dialog('close');        // close the dialog
				$('#finance_table').datagrid('reload');    // reload the user data
            }
        });
    }

    //删除
    $("#delete").click(function () {
		var row = $('#finance_table').datagrid('getSelected');
		if(!row){
            layer.msg("请选择需要删除的项目",{icon: 2})
		}else{
            url = '/finance-ins-upd-del/'+row.id;
            $.messager.confirm('删除信息','确定删除此项目?',function(r){
                if (r){
                    $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){                        
						$('#finance_table').datagrid('reload');    // reload the user data
                    });
                }
            });
		}	
    })
	$('#export').click(function(){
        window.location = "/finance-download";
    });
</script>

<script type="text/javascript">

    $("#searchByParameter").click(function(){
        var pro_name_like = $("#pro_name_like").val();
        var handler = '/search-proName/1/20?pro_name_like='+pro_name_like;
        $('#finance_table').datagrid('options').url = handler;
        $('#finance_table').datagrid('reload');
    });
</script>
<#--格式化数据，逐条进行-->
<script type="text/javascript">
    function proIdFormatter(val){
        console.log(val)
        var result = '';
        var url = '/pro_Id_Name/'+val;
        $.ajax({
            url : url,
            async : false,
            success : function (data) {
                result = data.proName;
            }
        })
        return result;
    }
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#finance_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
				var handler = '/finance-list/'+pageNumber+"/"+pageSize;
				$('#finance_table').datagrid('options').url = handler;
				$('#finance_table').datagrid('reload');
			}
		});
	})
</script>